<?php
    $count = count($productImages);
    if ($count > 0) {
?>
<script type="text/javascript">
    $(document).ready(function() {
        $("a[rel=image_group<?php echo $product->getProductId() ?>]").fancybox({
            'transitionIn' : 'elastic',
            'transitionOut' : 'none',
            'titlePosition' : 'over',
            'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
                return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
            }
        });
    });
</script>

<p>
<?php
    $idx = 1;
    foreach ($productImages as $productImage) {
        $class = "";
        if ($idx == $count)
            $class = "last";

        echo "<a rel='image_group".$product->getProductId()."' href='/uploads/products/".$productImage->getImageSrc()."' title='".$productImage->getImageTitle()."'><img alt='".$class."' src='/uploads/products/thumbnails/".$productImage->getImageSrc()."'/></a>";
    }
?>
</p>
<?php } ?>